﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Utility.Math
{
	public static class Factorial
	{
		static List<long> factorials = new List<long> () { 1 };

		public static long Get (int n)
		{
			if (n < 0)
			{
				throw new System.Exception ("factorial of negative number is invalid: " + n);
			}
			for (int i = factorials.Count; i <= n; i++)
			{
				factorials.Add (i * factorials[i - 1]);
			}
			return factorials[n];
		}
	}
}